<template>
  <el-form :model="form" label-position="top">
    <el-form-item label="映射的单元格名">
      <el-input v-model="form.mapColumn" @focus="focus" @change="change"/>
    </el-form-item>
    <el-form-item label="字段名">
      <el-input v-model="form.fieldName" />
    </el-form-item>
    <el-form-item label="字段描述">
      <el-input v-model="form.label" />
    </el-form-item>
    <el-form-item label="是否必填">
      <el-switch v-model="form.req" />
    </el-form-item>
    <el-form-item label="是否更新">
      <el-switch v-model="form.needUpdate" />
    </el-form-item>
    <el-form-item label="是否新增">
      <el-switch v-model="form.needInsert" />
    </el-form-item>
    <el-form-item label="默认值">
      <el-input v-model="form.defaultValue" />
    </el-form-item>
    <el-form-item label="表达式">
      <el-input v-model="form.expression" />
    </el-form-item>
    <el-form-item label="sql类型">
      <el-select v-model="form.dataset.dsType" clearable placeholder="请选择：">
        <el-option
          v-for="item in configData.dsTypeList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="sql">
      <ts-code-editor
        style="width: 100%"
        v-model="form.dataset.sql"
        :height="300"
      ></ts-code-editor>
    </el-form-item>

  </el-form>
</template>
  <script setup>
import { ref, defineModel } from "vue";
import { ElMessage } from "element-plus";
import tsCodeEditor from '@/components/scCodeEditor/index.vue'
const emit = defineEmits(['changeRange'])
const form = defineModel();
const oldMapColumn = ref()
const props = defineProps({
  configData:{type:Array,default:[]}
})
const focus = () =>{
  oldMapColumn.value = form.value.mapColumn
}
const change = (val)=>{
  const regex = /^[A-Z]+[0-9]+$/
  if(regex.test(val)){
    emit('changeRange',{newValue:val,oldValue:oldMapColumn.value})
  }
  else{
    ElMessage({
    message: '输入格式不符合',
    type: 'warning',
  })
  }
}
</script>
  